Use textwriter

Use TextWriter to write the output