On most servers, the webserver runs under a different user/group (usually nobody/nobody). When you access install.cgi from the web, it is run using this user, and so if the permissions aren't set correctly, this user won't be able to write or create the necessary directories. You can fix this problem by setting the permissions to be enough that the web user can write to the directory that you wish to install to. chmod 777 /home/username/public_html/cgi-bin/webmail 777 will do this.
Adrian
Adrian