Fixing DistCopy - flush stream before moving tmp file