Typing into Terminal works, AppleScript partially works
What can I do to make my AppleScript run things just like they run in Terminal?

Well, you could tell the Terminal app to run your command:
tell application &quot;Terminal&quot; to do script &quot;youtube-dl  &quot; &amp; input

But, I don't recommend this route, because it will actually open a Terminal window!
There are a whole host of differences between do shell script and typing commands into the Terminal. For starters, do shell script commands are run via sh, rather than the more advanced bash or zsh (And, your &quot;#!/bin/zsh&quot; shabang line at the top will have no effect in an Applescript!).
As to your actual problem, it sounds like youtube-dl can't find your copy of ffmpeg—probably because another difference between the Terminal app and do shell script is your PATH is set differently. Try specifying the location of your ffmpeg binary with youtube-dl's --ffmpeg-location flag.
If it helps to have a reference to look at, here is an Applescript I use to download videos from my web browser with youtube-dl. Note that I've been tweaking this for many years, so it has accumulated a lot of error checking, and code for compatibility with different browsers. Don't be intimidated! https://gist.github.com/Wowfunhappy/c2c8fc097a8b4f47430811fc1d0da041