Is this hidden form element code on the confirm page?
Usually with shipping rate lookup, it is triggered when the checkout page posts to the confirm page, then again when the confirm page posts to itself.
Are you getting the failure when the checkout page posts to the confirm page? What is the value of the shipping_postcode form element on the checkout page?