Use `try finally` to auto close writer