Run doctests from a temporary directory

Fixes #1821

@embray - is this the right approach? (wasn't sure, hence why I didn't attach the code to that issue)