Ah, found the problem actually...
[04-May-2007 13:32:24] PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 2746271 bytes)
Extended memory limit of PHP script to 32M and now it's working just fine. Could this code be optimised to not use so much memory?