You need to have the permissions set so that the httpd user (usually nobody) can read and write to the files/directory. If you don't know what user it runs as, then the files in the template directory should be set to 777 as well.
The user that the httpd runs as doesn't have enough permissions to write to the file. You probably want to chmod 777 the globals.txt.
You'll want to type in:
in the Code field (the left one)
return isset($HTTP_SERVER_VARS["HTTP_REFERER"]) ? $HTTP_SERVER_VARS["HTTP_REFERER"] : "nowhere";
Then Save changes.
Remember that with the PHP templates, and the globals for these PHP templates, you can use any valid PHP code. You CAN'T use Perl code in the templates or the globals.