using streamWriter prevent memory leak