in reply to Opening a Document in its Native Application

You need to send a Content-Type header back to the browser. For instance
Content-Type: img/gif
With CGI you can do this by passing a -type argument to the header function. Like this:
print header( # Stuff -type => "img/gif", # more stuff );