This path/directory stuff is a duplicate of code in tools/gen_rules.py - could do with refactoring. For example:
```
import some_shared_module
...
module_path = some_shared_module.output_module_path('iris.fileformats.ff_xrefs')
with open(module_path, 'w') as module_file:
    some_shared_module.write_header(module_file, 2013, 'gen_stash_refs.py')
    ....
```