Are you running from the shell as the same user that is running your
code in the webserver?
If, however, you are running under a web server, such as Apache, then
it will be running under the Apache user's account.
Any process can write to /tmp, so that of course should always work,
but it's not the best place to put log files.
Presuming you are running the development server, I would check to
make absolutely sure the filename string is what you expect it to be.
You can easily check this by adding a "print filename" above that line
of code, and checking the dev server's console.
/Gwyn