Add pdf() to capture the bias plot
Add folder slashes after reading and writing with "dir"

This is how I imagine it was supposed to be (files were getting written
over otherwise), but this needs to be checked.