Fix pretty big bug writing to the wrong directory