Stop using write_csv and write_csv_header during optimize.

This resolves issue #532 for CmdStan.  This issue also likely needs to be resolved for RStan and PyStan separately.