Writing files to external location (TODO: find out what is this suspicious tail at the end)