Hi,
Use the IO library as discribed earlier to write a string to a file.
You don't need to write this long JS code.
Add Generic Object Action step, choose Get Property (visible text) save it to some varibale and persist it to the file.
Much simplier.
Thanks