The create_new_library method first checks the existence of the library, and then creates the library only if it does not exist.
However, when checking existence, it uses library_name, while when creating it uses safe_name. If the library_name is not equal to the safe_name, the next time the library existence check will not succeed, however creation of the library would also fail - because the function attempts to create a different name.
The correct logic would be to convert the library name to the safe name as early as possible, and conduct further manipulations (checking existence etc.) with the safe name.