Fixed append_file() not closing on exceptions