Fix ordering of INPUT/OUTPUT logging
It used to be random, leading to inconsistencies between the reference output and the actual one in tests Now we order the outputs when logging. Note that the ordering (and the logging) is only done in debug mode