The prob I was having was that in the cron/su situation, $ENV{USER} wasn't getting set, although it turns out LOGNAME is. I also came up with about 3 other ways ie parse $ENV{MAIL}, $ENV{HOME} and POSIX::cuserid().
I'll prob use some or all of them similarly to your soln.
Cheers
Chris
Turns out that the prod servers generally have local accts, but my Solaris desktop uses LDAP ...