Private/Storage/FlatFile/Set-PukFlatFileStore.ps1

function Set-PukFlatFileStore {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Internal write helper always called by Set/Remove-PukFlatFileRecord after their own ShouldProcess gate has already approved the write; a second prompt here would double-prompt the user.')]
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [string]$Path,

        [Parameter(Mandatory)]
        [System.Security.Cryptography.X509Certificates.X509Certificate2]$Certificate,

        [Parameter(Mandatory)]
        [psobject]$Store
    )

    $directory = Split-Path -Path $Path -Parent
    if ($directory -and -not (Test-Path -LiteralPath $directory)) {
        New-Item -ItemType Directory -Path $directory -Force | Out-Null
    }

    $encrypted = Protect-PukFlatFileData -InputObject $Store -Certificate $Certificate
    Set-Content -LiteralPath $Path -Value $encrypted -Encoding utf8 -Force
}