moved file write outside of class