writing matrix to file