The code you are referencing is specifically for NodeJS, it cannot run as-is in Workflow.
Instead, store all the values you want to write to a file inside a variable or a Job Info. For instance:
Watch.SetVariable("myVariable", "This is the text to write")
Watch.SetJobInfo(9,"This is also some text to write")
Then, immediately after your script, use a Create File task that only contains your variable:
After that, you can use a Send To Folder task to store that newly created file anywhere you want.
Note that it’s also possible to write to a file directly from inside the script, but it requires a bit more code and the above method is usually more than adequate.