write mem to files