If you can't change the timeout (which I suspect you cannot) consider running the script from the command line (though I'm not sure totally if the safe mode will still catch you here, I don't have this restriction). Also, since I am curious, I had to run your script and did get the timeout. Looking at the output, you might want to consider grouping the sites you are spidering and getting them at intervals, basically running the same script over and over but getting different links each time. Just a thought, especially if you can't change the timeout var.
amc