added toTokFile function so writing to the file doesn't happen until after checkign for all errors from all stages of compiling.