Is this a case where you run the first script from the command line, but run the other page from a server (presumably apache) context? If so, then you are probably running into a common problem. The script that is failing is running in the context of the web server. It may not be running with the user, environment, nor pwd that you expect.