I think that here, as with so many other things, the answer is somewhere in the middle. It is technically correct that a willfully withheld unconfessed mortal sin can invalidate a confession. However, it is hard to tell from the original post whether that’s what went on here–even the OP posts with some measure of doubt in recounting something that happened a good while ago. I barely remember the last time I went to confession, like a week and a half ago, much less a confession I made in August, and I definitely don’t remember how I was feeling or what my mental disposition was like with any of my confessions. So it’s possible that the OP was not as culpable for withholding the sin as he might be remembering. Sometimes after the fact anxiety can make things seem worse than they really are.
So all that said, while it is technically correct that, absent any other circumstances, willfully withheld mortal sin invalidates a confession, it is impossible for us on the internet to know what really went on. I would advise the OP to follow what his confessor said, and to be at peace. It is better to deal with these things in person, with a priest, than to put one’s own motivations and one’s own priest’s pastoral care on trial on the internet among strangers with no intimate knowledge of the situation. It’s better not to continue letting this get to you. It sounds like there was sufficient doubt and uncertainty that it shouldn’t have been a problem, so I would follow what your priest said and move on.
-Fr ACEGC