write matrix to csv