Ensure the printwriter is always closed.