Gold closes higher to end two days of losses as dollar weakens