But we can use 'needn't like a modal verb in negative sentences like : You needn’t buy any eggs. We have plenty at home.
I couldn't get that why the first sentence I wrote is incorrect. Is it because of the pronoun 'you' ?
'Needn't' is modal, as you've said.- the form is <subj> +needn't + <verb>....<etc>.
You can't follow 'needn't' by anything but a verb [off the top-of-my-head - I wouldn't be surprised if someone found a counter-example ]
You'll see from 5jj's example that if you're talking about someone else's obligation - and you want to specify a subject for the following verb - you don't say 'needn't'; you use '<subj> don't need <do-er> to'. To use your example. 'You needn't buy eggs' could also be 'I don't need you to buy eggs'.