One answer is that in your first sentence, him is the indirect object; in the second, him is the direct object. PS: I mean, conceptually. To make it a grammatical indirect object, I can omit the to : She hasn't written him for a long time .
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.