updating script to write in binary mode