Move debug file creation to the sugar script

It needs to happen as early as possible and it's more
readable in a shell script then in python code.