Of course, if you're using http to connect to the server (a reasonable assumption), then you don't need to actually create a file on the server just to download it; the browser doesn't care where the contents of any given http response comes from, only what is in the headers (a content-type of text/comma-separated-variables, text/plain or application/octet-stream to stop IE from trying to use Excel to open it, a content-disposition giving a filename, etc.); the script can generate and output that CSV the same way it can generate and output HTML and, given the appropriate headers, the browser will deal with it appropriately.
The upshot is that there probably won't be any filesystem functions used at all. You request the CSV, the server uses the database to generate it and sends it as the response for you to download.
This can be automated (e.g., any suitable client will do, such as wget; it doesn't have to be a browser).