"Needn't have done" or "didn't have to do"
Hello!
I came across an exercise that requires to fill in the gap, choosing between "didn't need to bring " and "needn't have brought" in the following statement: "You _______________ the coursebook with you. That was the reason why the teacher yelled at you". According to the keys, the correct answer is "needn't have brought". The following explanation is given to clarify the choice: "When something was not necessary, but you did it, you can use either needn’t have + past participle or didn’t need to + infinitive: We needn’t have booked/didn’t need to book. The restaurant is empty!" IMHO the explanation has nothing to do with the task.
Hence... questions.
Is it possible to use "didn't need to bring" in this situation (my guess is "not"?) If not, why do we choose "needn't have brought"?
Thank you!