in reply to using multiple input files

Would the below code to it for me
I think you should answer that question. When you run your code, does it work the way you expect? If not, you should try to explain to us how it deviates from your expected behavior. Since we do not know what's in one of your input files ("temp3"), we can not run your code.

General suggestions:

Update: added chmod/unlink