in reply to CGI: print a gif directly from a print statement

All you're printing with your print statement is a list of the decimal equivalents of the hex numbers you've listed (instead of the character representation).
You could use pack, but in the past, I've done this using:
print "\x47\x49\x46\x38 . . .


Impossible Robot