Use StringWriter to temporarily store the output text before writing it to disk