Let's start with some basics before going too deep.
What OS and webserver are you using? Different webservers can easily provide different environments. Especially on the less critical variables, I would imagine.
Any possibility of a typo? If the print "$key = $ENV{$key}<p>"; line works, then there would be no reason for the other code to work except for keys that aren't quite right (such as in a typo).
Any reason to not use CGI to get all this? You're far more likely to get a compile or run-time error that makes things very obvious that it's going wrong if you use an existing module. Typos and the like will already be dealt with.