Translation:I write a letter to my friend.
i think it means ''him'' not ''them'' as translation suggests, so '' i write a letter to him (my friend)''.
You're right, ”îi” is the dativ form of the personal pronoun masculin and feminine ”el”-”ea”, so ”to him” or ”to her”.
literally, this is "I to him write a letter to my friend". 'ii' refers to the same person as friend, but just anticipates that later dative with a dative precursor.
In fact, it is also equally correct without ”îi” : ”eu scriu o scrisoare prietenului meu”.
Its similar to Spanish, you could say: Yo LE escribo una carta a mi amigo even though the LE is unnecessary