Hi,
Are you system administrator in the machine which have the script?
Your question "is not perl related" I think. You can configure the script timeout in webserver's configuration file.
As merlyn said, you are trying to do tasks that isn't supposed to do by a CGI.
Use better a non CGI script to do this jobs.