Building key file from list of lines