First of all: great work! I was about to write my own script for collapsing image stacks, when I stumbled upon yours.
Since the Dockerfile specs let you combine as many ENV entries as you want in a single line, it would be quite nice when the script would perform this optimization (to get rid of all the 0-Byte dummy layers).