Fixed the file output code having NullPointerException.