Both are correct, but they might have different meanings.
If A says to B "Write to me when you want" , this may imply that B is only going to write once. For example, if B asks if she should write a particular letter tomorrow or next week, A could say she doesn't mind when B writes it. Either tomorrow or next week would be fine.
"Write to me whenever you want" might imply that B is going to write many times. A could be saying that she is happy to receive lots of letters at any time. Any time that B feels lonely, she knows that she can write A a letter. This is what the word "whenever" could suggest.
By the way, you'll see that I've said "write to me" in my examples. "Write me" is used by American English speakers - you can say this if you want, but it isn't correct anywhere apart from the USA.