You mustn't do means that it is necessary that you do not do something. Let's see the following examples.
You needn't do means that it is not necessary that you do something. Let's see the following examples.
Needn't do can be replaced with doesn't/don't need to do. So, the two sentences above can be rewritten this way:
We use needn't have done to say that it was not necessary to do (in the past). Let's see the following examples.
Didn't need to is different from needn't have.
We use didn't need to to say that an action was unnecessary. This was known at the time of the action. Let's see the following examples.
When we use needn't have, it was not known at the time that the action was not necessary. Let's see the following example.
In this exercise you have to complete the sentences with needn't or mustn't !