Both “to” and “for” can be used with the verb “to write” but the meaning is different.
Gerardo wrote a letter to me. = He wrote me a letter. (I was the person who got/received the letter.)
Gerardo wrote a letter for me. (The letter was sent to Jane. I could not write the letter because my hand was broken.)
https://forum.wordreference.com/threads/write-for-to-you.3122112/