I assume you were trying to copy a file to a folder /opt/lib to create /opt/lib/file, but the directory didn't exists so you ended up creating a file called /opt/lib instead. If this guess is wrong, ignore this post.
I would be inclined to give the file its original name, create the directory and then move the file to the directory, like this:
although if the original file still exists, deleting the copy, making the directory and then copying would be OK too:
mv /opt/lib /opt/file
mv /opt/file /opt/lib/
cp file /opt/lib/