why does this give invalid file descriptor error when run
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#define MAXLINE 256
#define MAX_PASSWORD 10

#define SUCCESS "Password verified\n"
#define INVALID "Invalid password\n"
#define NO_USER "No such user\n"

int main(void) {
    char user_id[MAXLINE];
    char password[MAXLINE];

    if (fgets(user_id, MAXLINE, stdin) == NULL) {
        perror("fgets");
        exit(1);
    }
    if (fgets(password, MAXLINE, stdin) == NULL) {
        perror("fgets");
        exit(1);
    }

    int fd[2];
    if (pipe(fd) == -1) {
        perror("pipe");
        exit(1);
    }

    pid_t pid = fork();
    if (pid == -1) {
        perror("fork");
        exit(1);
    }

    if (pid == 0) {
        close(fd[0]);
        dup2(fd[1], STDOUT_FILENO);
        close(fd[1]);
        execlp("./validate", "./validate", NULL);
        perror("execlp");
        exit(1);
    } else {
        close(fd[1]);
        close(fd[0]);
        int status;
        wait(&status);
        close(fd[0]);
        if (WIFEXITED(status)) {
            int exit_status = WEXITSTATUS(status);
            if (exit_status == 0) {
                printf("%s", SUCCESS);
            } else if (exit_status == 1) {
                printf("%s", INVALID);
            } else if (exit_status == 2) {
                printf("%s", NO_USER);
            } else {
                printf("Unknown error\n");
            }
        } else {
            printf("Unknown error\n");
        }
    }

    return 0;
}
