Second code example:
fileURL = saveFile("export.csv", jsonStr);
(you should be writing csvStr to the file, not jsonStr) fileURL = saveFile("export.csv", jsonStr);
(you should be writing csvStr to the file, not jsonStr)