Instead of "subtract", it is easier to "try to avoid".
Sort all edges first by their weights, then by whether they belong to $T$. In other words, for any two edge $e_1$ and $e_2$, $e_1$ precedes $e_2$ if and only if
- $w(e_1) \lt w(e_2)$, or
- $w(e_1) = w(e_2)$ and $e_1$ does not belong to $T$ and $e_2$ belongs to $T$
The above order can also be realized by just increasing all weights of edges in $T$ by a small enough amount, such as $\frac d2$, where $d$ is the minimum positive difference between weights of any two edges.
Run Kruskal's algorithm or Prim's algorithm as usual using the above order of the edges instead of the usual order which sorts the edges by weights only. Since the edges are ordered by their (original) weights still, we will obtain a minimum spanning tree, which is $T'$.
On the other hand, you idea to "subtract" works as well.
Let $S$ be the all edges of $T$. For each edge $e\in S$ from the lightest to the heaviest,
- remove $e$ from $T$. $T$ becomes two disjoint trees
- check whether there is an edge other than $e$ of the same weight that connects those two disjoint trees.
- If we are able to find one, add it to $T$.
- Otherwise there is no such edge. Add $e$ back to $T$.
- return $T$, which may or may not have been changed, as $T'$.
However, the algorithm above is harder to implement and probably slower as well.