converting to using ofstream for binary output