diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py
index e30ee9c39f9a09245d37d1491f5f594995ab4e7d..925eb213c3f547b4495272df67c72616b5b15339 100644
--- a/binarycpython/utils/grid.py
+++ b/binarycpython/utils/grid.py
@@ -1422,8 +1422,9 @@ class Population:
                 )
 
                 # Write to file
+                ensemble_output = extract_ensemble_json_from_string(ensemble_raw_output)
                 with open(output_file, "w") as f:
-                    f.write(self.format_ensemble_results(ensemble_raw_output))
+                    f.write(self.format_ensemble_results(ensemble_output))
 
                 print(
                     "Thread {}: Wrote ensemble results directly to file: {}".format(