Fix bug with empty or non existed output file