diff --git a/bin/hicstuff_build_matrix.py b/bin/hicstuff_build_matrix.py
index c8bf3e49fd48a490ccd7221881bffef480dee318..8c47ac311b89a0ab3a11f765757f5d953a0d0ec6 100755
--- a/bin/hicstuff_build_matrix.py
+++ b/bin/hicstuff_build_matrix.py
@@ -72,7 +72,7 @@ def pairs2matrix(
     # )
 
     cmd = 'grep -v ^# %s | sort -S 2G -k8,8n -k9,9n --parallel=1' % pairs_file
-    with open(pre_mat_file, "a") as fout:
+    with open(pre_mat_file, "w") as fout:
         fout.write(str(os.system(cmd)))
 
     header_size = len(hio.get_pairs_header(pre_mat_file))