вы можете распечатать в файл следующим образом:
# open a file handle in append mode
txt_file = open('samplefile.txt', 'a')
# print with file argument will direct the output to the file
print(data[i], file=txt_file)
# close the file handle
txt_file.close()
Поместив это в ваш l oop:
data = []
txt_file = open('samplefile.txt', 'a')
for i in range (len(capfile.packets)):
data.append((ip.IP(binascii.unhexlify(ethernet.Ethernet(capfile.packets[i].raw()).payload))))
print(data[i], file=txt_file)
txt_file.close()