With a couple of ways to create CSV mentioned it may be time to ask "what flavor of text file?" Other than CSV (comman separated values) there are other characters used to separate each value. Common choices are tab and pipe (|) characters, less frequently colons or semicolons. Sometimes multiple characters.
Or maybe fixed width where each column (variable) has text start in the some character position.
Or maybe something less common like Named output where you indicate a variable name followed by an = and the value, which would include quotes when there are spaces: somevar="This a named value"
Or perhaps other specific text file formats like JSON, XML or similar.
Or even a report layout?