"I write a letter to my friend."
Generally に indicates that there is a motion towards the noun before it. So in this case, the letter is send towards your friend. With ある and いる you also use に, but then に just specifies the location. You can think of it as an excepion (though I think I read that there is a deeper reason for it, but I can't remember it). There are more verbs that take different particles than for example in English, so you should just learn these.
に can also used to specify time (九時に = at 9 o' clock). You don't use に with relative times, such as tomorrow, yesterday etc.