Fix file.replace bug when replacement str is numeric

Fixes #9097 and includes a unit test.