Your observation is essentially the following (where $\,n\ge 1$)
Theorem $ $ If $\,p\,$ is an odd prime and $\,b = 2^{\large p^{2n}-1}\!-1\,$ then $\,p\mid b.\,$ If $\,p^2\mid b\,$ then $\, p^2\mid 2^{\color{#c00}{p-1}}\!-1\,$ i.e. $\,p\,$ is a Wieferich prime. Hence $\,(p^n,b) = p\,$ if $\,p\,$ is not Wieferich.
Proof $\ $ $p\mid 2^{\large p^{2n}-1}-1\,$ by $\,p-1\mid p^{2n}-1\,$ and Fermat's little Theorem.
If $\,p^2\mid b\,$ then $\!\bmod p^2\!:\ 2^{p(p-1)}\!\equiv 1\equiv 2^{\large p^{2n}-1}\!-1\,$ so $\,2^{\:\!\color{#c00}{p-1}}\!\equiv 1,\,$ by $\,\color{#c00}{p\!-\!1} = (p(p\!-\!1), p^{2n}\!-\!1)$
Remark $ $ The proof still works if we replace the power $\,p^{2n}\!-1\,$ by any $\:\!k\,$ with $\,p\!-\!1\mid k,\ p\nmid k$.
Note that there are very fast (essentially linear time) algorithms for testing and decomposing perfect powers - see the paper of Bernstein cited in this answer.
return a factor of $N$ ?
I found that if it works for a generic A it works for another A= p-A || p-1 || p || p+1 || p+A ; where p is a factor of N
– Alberico Lepore Oct 19 '24 at 18:02