"I am writing him a love letter."
Translation:Je lui écris une lettre d'amour.
You're writing it to him, so that would be the indirect object. The pronoun for "il" when it is the indirect object is "lui".
If you were to change the sentence and assume that you've already mentioned the letter but not the person you're writing it to you could say "je l'écris à Paul" (I'm writing it to Paul). The letter is the direct object and so the pronoun is "la" which gets shortened to "l' ".
Maybe I can explain better like this:
Who is doing the writing? --> subject of sentence (je, tu, il/elle, nous, vous, ils/elles)
What is being written? --> direct object (me, te, le, la, nous, vous, les)
Who is it being written to? --> indirect object (me, te, lui [for both masculine and feminine when in front of verb], nous, vous, leur)