Solved it. Reading around here https://github.com/ingrammicro/puzzle-publisher/blob/master/PuzzlePublisher.sketchplugin/Contents/Sketch/exporter/exporter.js I saw they initialized an error like this:
var error = MOPointer.alloc().init();
Doing so I was able to get an error in the var, which told me this:
Incorrect NSStringEncoding value 0x0000 detected. Assuming NSASCIIStringEncoding. Will stop this compatibility mapping behavior in the near future.
error: Error Domain=NSCocoaErrorDomain Code=517 "The file “file.txt” couldn’t be saved using text encoding Western (ASCII)." UserInfo={NSFilePath=/Users/xxxxxxx/Desktop/file.txt, NSStringEncoding=0}
So I just changed the writeToFile to this:
var result = s.writeToFile_atomically_encoding_error(path, true, 4, error);
(1 instead of UTFEncoding). Works for now.