Typically, such problems are the result of environment differences -- in this case, the CGI-script is most likely not running as the same user that you are using to run the copy on the command line. Thus, it fails. Make sure that your CGI user has the permissions to perform this copy as well.