Refactor tee.c

use err_exit method
fix warning when compiled with -Wall --pedantic flags