The current directory (root) is not associated with a file error when looping over input files

Before “out_tree->Write();”, try to add: out_file->cd();