Problems connecting to Oracle are often caused by required environment variables that aren't set. See what you have in your normal environment where it works, in environment variables that start with the prefix "ORA", for example "ORA_HOME". If you set them the same way for the CGI script, it'll probably work.