Congratulations on choosing Node-red then, a programming language where you can do most things without Javascript, or any procedural language whatsoever
You do not need discrete flows to create a file and then to write to it.
Here is a sample flow which injects some sample data, converts it to CSV format and writes it to a file.
You can import, deploy and play with it. You will probably need to change the output file pathname.
I have simplified setting msg.filename because you didn't say how you derive this, nor include and sample data.
Input data
[
{"name":"Night Riviera","from":"Paddington","departs":"23:45","to":"Penzance","arrives":"07:07"},
{"name":"Caledonian Sleeper","from":"Euston","departs":"20:20","to":"Fort William","arrives":"10:00"}
]
Complete message passed to write file node.
NB the data is in msg.payload
and the filename in msg.filename
{
"_msgid":"7a6f48fd9fe2ccd5",
"payload":"Night Riviera,Paddington,Penzance,23:45,07:07\nCaledonian Sleeper,Euston,Fort William,20:20,10:00\n","topic":"","columns":"name,from,to,departs,arrives",
"filename":"/home/pi/junk.csv"
}
Copy and import this code into your Node-red
[{"id":"ca11361396e92b08","type":"file","z":"278bd8f3b69d98a3","name":"","filename":"filename","filenameType":"msg","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":720,"y":100,"wires":[[]]},{"id":"d2fd467a91221e97","type":"csv","z":"278bd8f3b69d98a3","name":"","sep":",","hdrin":"","hdrout":"once","multi":"one","ret":"\\n","temp":"name, \"from\", \"to\", \"departs\", \"arrives\"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":330,"y":100,"wires":[["681b847fdbd88f7a","045535e0759d75ca"]]},{"id":"05f55bde8999fdfc","type":"inject","z":"278bd8f3b69d98a3","name":"Sample Data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"name\":\"Night Riviera\",\"from\":\"Paddington\",\"departs\":\"23:45\",\"to\":\"Penzance\",\"arrives\":\"07:07\"},{\"name\":\"Caledonian Sleeper\",\"from\":\"Euston\",\"departs\":\"20:20\",\"to\":\"Fort William\",\"arrives\":\"10:00\"}]","payloadType":"json","x":110,"y":100,"wires":[["88763cb2819cf638","d2fd467a91221e97"]]},{"id":"88763cb2819cf638","type":"debug","z":"278bd8f3b69d98a3","name":"Input payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":300,"y":60,"wires":[]},{"id":"681b847fdbd88f7a","type":"debug","z":"278bd8f3b69d98a3","name":"As CSV","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":500,"y":60,"wires":[]},{"id":"045535e0759d75ca","type":"change","z":"278bd8f3b69d98a3","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"/home/pi/junk.csv","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":100,"wires":[["ca6daab9bc59599b","ca11361396e92b08"]]},{"id":"ca6daab9bc59599b","type":"debug","z":"278bd8f3b69d98a3","name":"Complete msg object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":60,"wires":[]}]