Use Post::File methods when possible. They try to be multiplatform and multisession. The write_file method looks good to be used here.