in reply to Opening a Document in its Native Application

a cgi script that opens a document

No such thing. A CGI script serves a document, it is up to the receiving (client) side what to do about it.

Upon serving the document, mark it with the appropriate MIME type in the HTTP header, e.g.

Content-type: application/msword

You can do that with the header method/function of CGI.