write to the output file when provided

Reported-by: Joon Ro <joonhyoung.ro@gmail.com>
Signed-off-by: Aitor Soroa <a.soroa@gmail.com>