Your program works for me, but there's definitely something odd with that image. I can open it fine in Firefox, either with the URL or with the file downloaded by your program. But my regular image viewer (Eye of Gnome) crashes when I try to open the file, whether it's the one downloaded from Perl or saved from the Web browser. The file saved from the Web browser is identical to the file retrieved by your program.
However, if I convert the image with Image::Magick into an image with the same specs (I'm just running convert test.gif test2.gif), it will open up fine in my image viewer.
So, maybe your problem isn't with the Perl script, but with a weird image screwing up later steps in the process, and maybe Image::Magick can make the image less weird.