exec refactor

1) Eliminated some unnecessary loops
2) Switched file open from 'a'/'w' to 'a+'/'w+' (update modes) to avoid having to reopen it for reading
3) fixed bug in print_command routine due to buffering by 'print' where the command run was not written to the output file until after the command was run.
4) when appending to file, _exec would still read entire contents of file and return that as process output. This could include previous output in addition to output for the most recently run process. Not sure if this is what was intended? Added offset in file operation so that only output for the most recently run process (and the most recent append operation) is returned