Fixed bug in write to properly resize file.