utf8::decode of $description and $name provided further sources of script failure due to problem characters so I commented these out as a temporary fix.
The lines added to remove unicode problems added more unicode rather than removing it. The other changes were left because they remove unbreaking spaces that somebody else has inserted. There may be other unicode problems arising in the future for similar reasons with other characters appearing. Need a better all-round solution without compounding the problem as I did.