Subject: | Don't trust $ENV{USERNAME} |
On Unix systems there are situations where $ENV{USERNAME} has the wrong value. I can reproduce it on my Linux system like this:
$ echo $USERNAME
eserte
$ env | grep USERNAME
(nothing)
$ sudo su cpansand
$ echo $USERNAME
cpansand
$ env | grep USERNAME
USERNAME=root
Note that $USERNAME may be available as a shell local variable only. And also note that the values of a shell local variable and an environment variable may not be the same.
I think it's better to use again getpwuid() where it's available (Unix systems) and fallback to $ENV{USERNAME} or $ENV{USER} only on other systems (i.e. Windows).