[1.7.x] Fixed bad usage of rstrip() that caused test failure.

If the temporary file name contained a p or y as its last
characters, it would be stripped. refs #23083.

Backport of 57d2b3f2a7 from master