I\'ve created a file in Google Apps Script as follows
DocsList.createFile( \"test.csv\", \"Row1Col1,Row1Col2 \\r\\n Row2Col1,RowCol2 \\r\\n Row3Col1,R
Try using ContentService, you can trigger a download and even set the file name via the TextOutput.downloadAsFile method. You can also set the content mime type of the returned data, though only to a predefined enum constant. See their examples.