Prototyped file writing. Need to add some sanity checks.