in reply to open file error

Further explaining the problem Corion pointed out.

In your code, the string you assign to $run_cmd

"./tpsm -rules tpsm_rulesfile_ubuntu -looprf 0 -stop 10 -pspc 1 >logfile.txt "

has a trailing space.

That trailing space is the source of the extra space in $logfile when you do the split.