The dump file would be end up corrupted sometimes when working with mitmdump in a VM. Adding an explicit flush seems to have resolved the file sync issues.