"I write a letter to my friend."
I am confused with the usage of 'ni'. Sometimes it is used to specify position like 'shita ni imasu' here it is used as 'to' (to friend). Can somebody clarify this? Also if there are any more usages of 'ni'
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.
Instead of i write a letter to my friend i think it should be i wrote a letter to my friend or i am going to write a letter to my friend