I tried moving the bracket, that is not my problem as it made no difference.

There's some error in the function or the loop that is causing the local tax on shipping to be added into the total twice.