diff --git a/pystencils/cpu/cpujit.py b/pystencils/cpu/cpujit.py
index 745bbcc84292ab100cb9349fbbd5185659bcf582..ac1e8ac4f018b18ee331576ce87490b48d0ad6d1 100644
--- a/pystencils/cpu/cpujit.py
+++ b/pystencils/cpu/cpujit.py
@@ -602,7 +602,7 @@ def compile_module(code, code_hash, base_dir, compile_flags=None):
 
     if not os.path.exists(object_file):
         try:
-            with open(src_file, 'xw') as f:
+            with open(src_file, 'x') as f:
                 code.write_to_file(f)
         except FileExistsError:
             pass