Hi Dan,
I did not try to run your code (might be useful next time to enclose your code with back ticks) but from what it looks like, you need to change the line:
newtext = layer.replace(findText,replaceText)
to
newtext = name.replace(findText,replaceText)