Apache Checks the header of the file on the server to see if its close to the mime format.
So your error could be because your printing something befor the header " print "$url is ${width}x${height}\n"; ". It can Aslo be a Perl Error That the code is malformed or has some problems.