write states to file