Properly handle file:// URIs when trying to cache local files

This fixes a regression introduced between 2014.1.0 and now, likely
around the time when we moved to using the requests library. It allows
for local file paths (either prefixed with 'salt://' or not) to be
"cached" by simply returning the file path.
Don't allow templating of files when dest == source

This would clobber the template, so raise an exception.
Add tests for templating local files
Clean up filehandle usage in file state tests

This does a few things:

1. Change calls to open() to use salt.utils.fopen()

2. Use with blocks where applicable
Merge pull request #14228 from terminalmage/issue13873

Fix regression in templating local files