Shia LaBeouf turned rehab into a writing room for new film