in reply to Save HTML table as CSV on local disk

You want to trigger the browser's "Save as file" action, is that it?

In that case, instead of ouputing Content-type: text/plain or whatever you usualy output, try

Content-type=application/octet-stream; filename="some_filename"
Since people usualy don't have an application bound to octet-stream, most browsers should just save it.