When you run the script from a normal prompt, you're running it as your normal user account, not www. So I would think that it's still the sudo requiring password issue. Either run the script from the command line using sudo -u www (something like: sudo -u www perl /path/to/perl/script.cgi) or add your normal account to the sudoers file.