Make it easier to replace uitests

Lots of times we do a modification that will break some uitests. Its very
annoying to remove them all for them to be created again.
This makes it possible to define an environment variable to be used so the
failing uitests will be replaced.

Also, use 'with open()' instead of 'open' directly to make sure the files
buffers were closed, like when opening it for reading lines and them opening
again for overwriting it.

Change-Id: Id015614cd258e2396def9e3c9c4996382f4ab65e