To prompt the browser to save a file, you basically need to print out different headers than you usually print out for CGI. Normal CGI scripts print out:
Content-Type: text/html\n\n
You want something different. You want:
Content-Type: xxxxxxxx\n
Content-Disposition: attachment; filename="xxxxxxx"\n\n
You don't even really need to actually make the file, unless you want to keep a server copy for some reason. If so, then the best thing to do is to write to the file, close it, then read it back in, printing to STDOUT as you normally do. After printing the above headers, that is.
[edit]
"Are these the key elements I need to call the script?"
Um, sort of. They're the basics you'll need that are different from other CGI programming. Have you done any CGI programming before?
But check to see what output you're getting back. Print out the normal "Content-Type: text/html\n\n" headers ABOVE the other headers as sort of a debug line. That way, you can see what your script is returning more directly. And be sure to "view page source" in your browser to see the exact content.
Also, check your error logs to make sure there isn't some sort of other error in the code. If it's dying halfway through the page, you may get a blank screen or a 500 error, depending on where in the code it's breaking.
As for the headers, I don't know python, but they're recommending printing out:
print 'Content-Type: application/vnd.google-earth.kml+xml\n'
print kml
Which... seems wrong to me. The double "\n\n" is what is supposed to separate the header info from the document, so unless the print statement by default prints out an extra "\n", I'm not sure why that would work. Anyway, if you DON'T include the Content-Disposition, that's fine, the browser may decide to prompt you for the file or not. Depends on if the browser thinks it can handle that file type. The Content-Disposition of "attachment" is supposed to signify that the thing you're downloading should be saved as a file by default, not shown in the browser. So if you omit it, the browser will attempt to show it, if it thinks it can. If it doesn't recognize the MIME type, it will probably prompt you to save the file anyway...
[/edit]
DaveE