Safely append to file.