We are reading and writing each TestExpectations file multiple times regardless of whether there's actually any REBASELINE lines in the file or we actually did anything. A partial fix would be to only iterate over the set of unique expectations_dict() values, rather that all of the port names. Another would be to skip rewriting the file if get_rebaselining_failures() returned an empty set.