Fixed problem with empty network devices file

open and close the file in different places so information is written
before script gets terminated.