fix terrible bug in writing to files

"wb" rather than "w"