added a stringbuilder output to speed up the file writing part of the program