Better logging
Correct treatement of standard output
Added trick to not overwrite existing file