Close writer in finally block