Imagine someone bought you a gift and you say : "Thank you but
A) you didn't need to do this.
B) you needn't do this.
C) you didn't have to do this.
They are all grammatically correct, and the first and third are equivalent. The second one is also grammatically correct but has a different meaning:
Thank you but you didn't need/have to do this.
This means that you're thanking them, but what they did was unnecessary. For example, I might get you a cake. You could say Thank you, but you didn't need to do this!
Thank you but you needn't do this.
This means you're thanking something, but saying that what they are going to do is unnecessary. For example, I could find out that it's your birthday, and say I'm going to go and buy you a cake right now!. You might be grateful, but not want to inconvenience me. You could say Thank you, but you needn't do this! (or equivalently, Thank you, but you don't have to do this!).
If you want to change this sentence to have the same meaning as the other two, you could say
Thank you, but you needn't have done this.
It's social convention to use C) more often then anything else, B) is obviously you need not do this which is a little outdated for the 21st century and A) also works
hope this helps :)