Added unset for $line and $ports
Used PHP functions for rename and touch instead of system calls.