When I try your line of code on my machine using a non-existent username, I get a return value of
'' (not
undef). If you're testing for the existence of a user, then, you should be able to test
length $uid. If the return string has any length, then you have a valid user.
I would also recommend removing the double-quotes around $username, as this causes double-quotish processing to happen, which you may not want.