diff --git a/src/DataTree.cc b/src/DataTree.cc
index 69e7d938bf21d5c75eadcbf889f5822af1dfb363..e1f3e1042b335afb8094c9fc1f922a4c78ead210 100644
--- a/src/DataTree.cc
+++ b/src/DataTree.cc
@@ -978,6 +978,8 @@ DataTree::writeToFileIfModified(stringstream &new_contents, const string &filena
     return;
   old_file.close();
 
+  new_contents.seekg(0);
+
   ofstream new_file{filename, ios::out | ios::binary};
   if (!new_file.is_open())
     {