Uploaded image doesn’t show up in media library

The missing element that makes a file appear in the media library is the attachment post. Attachment posts hold the file metadata, and are what get associated to posts via the post_parent when a file is “attached”.

Instead of wp_handle_upload, you can use the function media_handle_upload, which will handle the file upload as well as insert the attachment post.