close output stream when copying files