I asked you four questions. You answered one question.
Without seeing some representative input to your script, it is really hard to guess why your program behaves as you say it does. Something is not as you think it is, otherwise your program would behave as is obvious. You keep on hiding the input file despite being asked for it. Maybe now is a good time to reconsider that stance.