Write somebody a letter = correct
or
Write a letter to somebody = correct
Write to somebody a letter is not correct
That's the structure for direct and indirect objects / objects of prepositions.
I bought my friend a present. Indirect object first, don't use a preposition.
I bought a present for my friend. Direct object first, use the preposition.