print last k lines of a file, problem in opening file twice