Fix bug that incorrect output file name was used