import binascii
with open('hexFile.txt') as f:
    with open('test', 'wb') as fout:
        for line in f:
            fout.write(binascii.unhexlify(''.join(line.split())))
Запись шестнадцатеричных данных в файл