Below link and attached an example & description how to write /read to/from CSV file.
https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclibutilities/html/tcplclibutilities_csv_sample.htm&id=