Arguably, those are both correct and possible ways to say it, it just depends a bit on the feeling/nuance you want.
I wrote it.
This is very matter-of-fact, and focuses entirely on the past. Therefore, because it doesn't say anything about the present, in the case of writing a letter, for example, if you didn't say otherwise, somebody might assume this to actually mean "I wrote it and sent it and it's all completed now", or at least that from your perspective, the whole thing is over and done with, etc.
I have written it.
This says that you are currently in the situation of having (previously) written it. Because this is talking about your present state, though, it has a feeling of incompleteness or continuing action, so somebody would be more likely to assume this means maybe you wrote it but you haven't yet sent it, or there is some other part to the process you haven't yet finished.
There is also another option you didn't mention (which I think may often be the most appropriate in that sort of case):
I had written it.
This is similar to "have written it" in that it suggests some degree of incompleteness (i.e. it was written but not sent, etc), but it's all in the past, which actually has an implication more of "at a point in the past, I wrote it, and then I was going to do something more (send it, etc), but I never actually did that part".
Also, if somebody had asked you, and at that point you had said something like "I don't know, I will have to check", and then you looked it up and got back to them later, in that sort of situation it would be common to say "I had written it" to indicate that at the time they were asking about it, it was already the case that you had written it (even though you didn't know it at that point). On the other hand saying "I have written it" (or "I wrote it") might mean that you had already written it, or it might instead mean that you looked it up, discovered you hadn't, then wrote it just now, so that you could now tell them that it was (presently) done.
However, that's just the feeling that they impart if used on their own. It is also possible to say more in addition to that which makes it clear exactly what you mean, in which case they can all be used for really any of the cases, for example:
- "I wrote it, but then I forgot to send it."
- "I have written it, and sent it."
- "I had written it and sent it some time ago."
and so on..
In such cases the only real difference is whether you want to focus more on your current situation ("have written"), your past situation ("had written"), or what your past actions were ("wrote").