I know that $opsys is setting correctly. I use it instead of $^O because it sets some other variables in the script as well as this.
The amount of corruption does vary from image to image and from browser to browser. I'm not sure what the reason is behind it. I wrote this script for a church and it's photos vary in corruption. You can see the images at
http://mtziontrenton.com/cgi-bin/ezwebalbum.cgi
With some images it was fine, with others it is a few lines, and others had major corruption.
If you have any idea about why this is happening, please let me know!