To avoid the ExtendScript Toolkit editor opening remove the line $.writeln(parentFolder);
$.writeln() writes to the javascript console in the editor and you scirpt opens the editor to complete that line.
If the extension is being removed by the saveAs method, I wouldn't worry about it.