At least on my Pi the hostname is set by the file /etc/hostname.
There is no direct tie in with the /etc/hosts file, other than for convenience.
If you are trying to use "sudo" to create a /etc/hostname, then you have to do it differently than:
sudo echo "$INPUT" > /tmp/newpi/etc/hostname
As this leaves you as the owner of the file, rather than root.
To do it try:
sudo bash -c "echo '$INPUT' >/tmp/newpi/etc/hostname"
Here the sudo executes bash, which is run as root. That bash process will then interpret the string to set the hostname (and since the redirection is done by the root bash, it gets owned by root).
Side comment... You might prefer the partitioning done this way - mostly due to it being easier to read:
# Formats sd card correcttly for bootable Raspberry Pi image
sudo fdisk /dev/sda <<-DONE
This would also make it simpler to read if the +100M were replaced by an environment variable.
Either way should work.