Hello, Kinga Zet—and welcome to English Forums. Thank you for registering as a member.
I wrote it much better than I did before. You don't need past perfect because the order of events is made clear by the word 'before'. However, you may mean this:
The tense of “wrote” is PAST TENSE. “did” is PAST TENSE. “wrote” is also PAST TENSE. However, “had done” is PAST PERFECT TENSE.
If you wish to express simple past tense, use the first sentence. If you wish to include the change in tense, use: “I wrote it much better than I had done ( it) before.” ( omit the word “it” as unnecessary.)