apply file permissions from input file to output file

This solves #28.

I didn't wanted to apply file permissions at different places (binary vs. non-binary files) so I decided to clean-up the code a bit. It's slightly different to the previous behaviour in the sense that basename of infile itself can now be templated (why shouldn't it?). I looked at the history of these lines and really couldn't figure out why it has been implemented this way. (If there are good reasons not to template the basename of infile, let me know.)