Now replacing descriptors using dup2, instead of dup or close and open file. Fixes potential issue where stdout and stderr might overwrite each other, due to being from different open calls.