When I was in cubicle environments at work, this situation happened on occasion. There were a few times that the person who was very visibly leaving had a cubicle that was next to mine, and I'd generally overhear these interactions. A few times, people who came to talk with me in my cubicle who I knew had just joined the company and had no interaction with the person noticed the clear signs they were leaving (including sometimes literal farewell signs on their cubicle door), and went to briefly wish them good luck on their future endeavors.
Different people are different, but I've never heard anyone responding badly to someone telling them goodbye and good luck, or whatever their equivalent words might be. I've never heard a person in the departing position asking, "do I know you?" unless the person telling them farewell was particularly verbose or nosy in their farewell address.
In several cases where I was well acquainted with the person leaving, they confided in me that they had met more people in their last week of being with the company than they had in all of the years they'd been with the company.
For what it's worth, I'm in the US, and work in IT. I'm not sure how much that matters. In any case, the person isn't going to be around much longer, and they'll be more focused on what is coming up next in their life. It's probably not going to be a big deal to them to have a few people they've never met tell them goodbye, amid the various people they do know.
Email will also probably not be a big deal if you choose to go that route, too. I haven't heard of any problems with people using that method to tell the person farewell, either. I've not had as much of an impression of how well that's received, but I was a company postmaster for a while, and if people had been bothered by it enough to put in an official complaint, I'd have been one of the people they would've been likely to complain to.
Whatever method you use, keep it brief and low key. There are some who give exuberant farewells, but that's best reserved for people one knows.
That having been said, this is an opportunity for a social interaction that will likely have no negative consequences as long as you don't make a big production of it and aren't negative yourself. While I'd only recommend choosing one of the two options, it might be a good time to take the option you are less comfortable with, to give you more practice with dealing with people in that fashion.
The preceding paragraph was advice I was given early on in my career, and while I did not always follow it, it's worked well for me every time I did. I've focused more on my observations with how others have fared following this advice, because on the one hand, I'm a white male who has always worked in companies run by white males, and on the other, I'm on the autism spectrum. As such, my personal experiences are in some ways favored, and in general not necessarily representative. In this case, the experiences I've observed others having have been consistent with my own.