An offset issue in s5_write_file
Re-arranged the code
Reviewed s5_write_file