Could it be a permission problem? You need to remember that your cgi program is run under a different user than yourself (the httpd or apache user if you are on a unix machine). The permission problem is the one that usually bites. One way to test this is to setuid to the web server user, and run the cgi script again.
There are other possible causes too, but check the permission first.