This is excellent as it demonstrates a bunch of concepts in a single file and is quite readable.
thinking out loud:
This might be a great tool for certain end to end test scenarios as the script could easily be templatized in order to pipe through sed to select difference binary responses ... and be checked in to have a immutable point-in-time version of the test response.
(edit: ps: I love single file pieces of code like this -- I once wrote a boot loader and "mini-os" in a single file for an embedded board. When I started telling people about it they loved it because they could literally read through the code like a word document and learn how I got it all to work)